import React, { useState } from "react";
import { ScrollView, View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import NavBar from "../NavBar";
import "./index.scss";

type PersonProps = {
    navBackground?: string;
    title: string;
    onBack?: () => void;
    children: React.ReactNode; // 添加children类型
    needBackIcon?: boolean;
};

const BasePageCom = (props: PersonProps) => {
    const {
        navBackground,
        title,
        onBack,
        children,
        needBackIcon = true,
    } = props;
    const [navHeight, setNavHeight] = useState(0);
    return (
        <View className="base-page-container">
            <NavBar
                needBackIcon={needBackIcon}
                title={title}
                navBackground={navBackground}
                goBack={() => (onBack ? onBack() : Taro.navigateBack())}
                updateNavBarHeight={(navH) => {
                    setNavHeight(navH);
                }}
            />
            <ScrollView
                scrollY
                style={{ maxHeight: `calc(100vh - ${navHeight}px)` }}
                scrollWithAnimation
            >
                {children}
            </ScrollView>
        </View>
    );
};

export default BasePageCom;

